<template>
	<el-dialog title="修改分组" width="800" v-model="visible" :close-on-click-modal="false" :destroy-on-close="true" draggable>
		<ApiConfigEdit @submitForm="updateApiConfig" :initialApiConfig="apiConfig" />
	</el-dialog>
</template>

<script setup lang="ts">
import ApiConfigEdit from './components/ApiConfigEdit.vue';
import request from '/@/utils/request111';
import { ElMessage } from 'element-plus';
const apiConfig = ref({});
const visible = ref(false);
const emit = defineEmits(['refresh']);

function getApiConfig(id) {
	let url = '/api/sys/api-configs/' + id;
	request(url, { method: 'GET' }).then((response) => {
		if (response.ok) {
			response.json().then((data) => {
				apiConfig.value = data;
			});
		}
	});
}
function updateApiConfig() {
	let config = { method: 'PUT', body: apiConfig.value };
	request('/api/sys/api-configs', config).then((response) => {
		if (response.ok) {
			ElMessage.success('更新成功！');
			visible.value = false;
			emit('refresh');
		}
	});
}
function openDialog(id) {
	visible.value = true;
	getApiConfig(id);
}
defineExpose({
	openDialog,
});
</script>

<style scoped></style>
